package com.huibei.wateradmin.merchant.controller;

import com.huibei.wateradmin.common.message.PageDto;
import com.huibei.wateradmin.common.message.ReqAdminListMsg;
import com.huibei.wateradmin.merchant.feignClient.MerchantFeignClient;
import com.huibei.wateradmin.merchant.message.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by wanglinlin on 2017/10/30.
 */
@RestController
@RequestMapping("/admin/merchant")
public class MerchantController {

    @Autowired
    MerchantFeignClient merchantFeignClient;

    @RequestMapping(value = "/shopListPage")
    public ModelAndView getShopListPage() {
        return new ModelAndView("merchant/shop_list");
    }

    @RequestMapping(value = "/shopList" ,method = RequestMethod.POST)
    public PageDto<AdminShopBaseInfoModel> getShopList(ReqAdminListMsg msg) {
        return merchantFeignClient.getMerchantList(msg);
    }

    @RequestMapping(value = "/createShop")
    public void createShop(ReqCreateShopMsg msg) {
        merchantFeignClient.createShop(msg);
    }

    @RequestMapping(value = "/productTypeListPage")
    public ModelAndView productTypeListPage() {
        return new ModelAndView("merchant/productType_list")
                .addObject("brands",merchantFeignClient.getBrands())
                .addObject("categories",merchantFeignClient.getCategories());
    }



    @RequestMapping(value = "/productTypeList" , method = RequestMethod.POST)
    public Page<AdminProductTypeModel> getProductTypeList() {
        return new PageImpl<AdminProductTypeModel>(merchantFeignClient.getProductTypeList(1L));
    }

    @RequestMapping(value = "/createProductType" ,method = RequestMethod.POST)
    public void createProductType(ReqCreateProductTypeMsg msg) {
        merchantFeignClient.createProductType(msg);
    }

    @RequestMapping(value = "/storeProductListPage")
    public ModelAndView storeProductListPage(Long shopId) {
        return new ModelAndView("merchant/storeProduct_list")
                .addObject("shopId",shopId)
                .addObject("productTypes",merchantFeignClient.getProductTypeList(1L));
    }

    @RequestMapping(value = "/storeProductList" ,method = RequestMethod.POST)
    public Page<AdminStoreProductModel> getStoreProductList(Long shopId) {
        return new PageImpl<AdminStoreProductModel>(merchantFeignClient.getStoreProductList(new ReqShopProductListMsg(shopId)));
    }

    @RequestMapping(value = "/createStoreProduct" ,method = RequestMethod.POST)
    public void createStoreProduct(ReqCreateStoreProductMsg msg) {
        merchantFeignClient.createStoreProduct(msg);
    }

    @RequestMapping(value = "/productListPage")
    public ModelAndView productListPage(Long shopId) {
        List<AdminStoreProductModel> storeProducts = merchantFeignClient.getStoreProductList(new ReqShopProductListMsg(shopId));
        return new ModelAndView("merchant/product_list")
                .addObject("shopId",shopId)
                .addObject("storeProducts",storeProducts);
    }

    @RequestMapping(value = "/productList" ,method = RequestMethod.POST)
    public Page<AdminProductModel> getProductList(Long shopId) {
        System.out.println(shopId);
        return new PageImpl<AdminProductModel>(merchantFeignClient.getShopProductList(new ReqShopProductListMsg(shopId)));
    }

    @RequestMapping(value = "/createShopProduct" ,method = RequestMethod.POST)
    public void createShopProduct(ReqCreateShopProductMsg msg) {
        merchantFeignClient.createShopProduct(msg);
    }

}
